package com.lovo.hb.dao;

import com.lovo.hb.entity.UserEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;
import java.util.Map;

public interface IUserDao extends CrudRepository<UserEntity,Long> {
   @Query(value = "select u.user_name,r.roleName from sys_user u LEFT JOIN sys_user_role ur on u.userId=ur.userId_fk " +
           " LEFT JOIN sys_role r on r.roleId=ur.roleId_fk where u.user_name=?1",nativeQuery = true)
    public List<Map> findAllRoleByUserName(String userName);

  @Query(value = "from UserEntity where userName like ?1",
          countQuery = "select  count(userId) from UserEntity where userName like ?1")
  public Page<UserEntity> findAllByLikeNameForPage(String userName, PageRequest pageRequest);
}
